<?php

namespace App\Http\Controllers\Api;

use App\Models\Area;
use App\Utils\CodeUtil;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class AreaController extends Controller
{

    public function province(Request $request){
        $list = Area::where("level_type",1)->get()->toArray();
        return response()->json(['code'=> CodeUtil::SUCCESS,"msg"=> "success","data"=>$list]);
    }
    public function city(Request $request){
        $parent_id = $request->input("id");
        $list = Area::where("level_type",2)->where("parent_id",$parent_id)->get()->toArray();
        return response()->json(['code'=> CodeUtil::SUCCESS,"msg"=> "success","data"=>$list]);
    }
    public function area(Request $request){
        $parent_id = $request->input("id");
        $list = Area::where("level_type",3)->where("parent_id",$parent_id)->get()->toArray();
        return response()->json(['code'=> CodeUtil::SUCCESS,"msg"=> "success","data"=>$list]);
    }
}
